package com.book.controller.file;

import com.book.service.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequiredArgsConstructor
@RequestMapping("/file/upload")
public class FileUploadController {

    private final FileService fileService;

    /**头像上传
     * @param file 文件
     * @return {@link String } 文件路径
     */
    @PostMapping("/user/avatar")
    public String avatarUpload(MultipartFile file) {
        String bucketName = "user/avatar";
        return fileService.uploadFile(file, bucketName);
    }

    /**图书封面
     * @param file 文件路径
     * @return {@link String }
     */
    @PostMapping("/book/cover")
    public String bookCoverUpload(MultipartFile file) {
        String bucketName = "book/cover";
        return fileService.uploadFile(file, bucketName);
    }
}
